package com.wing.productionPlan.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.enterprise.product.model.entity.ProductDetail;
import com.wing.productionPlan.dao.ProductionProcessDao;
import com.wing.productionPlan.model.entity.ProductionProcess;
import com.wing.productionPlan.model.request.DeviceTypeForm;
import com.wing.productionPlan.model.request.ProductionProcessForm;
import com.wing.productionPlan.model.response.DeviceOrWorkVo;
import com.wing.productionPlan.model.response.ProductionProcessVO;
import com.wing.productionPlan.model.response.ResBenchmarkBookEchnologyVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 生产工序表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class ProductionProcessServiceImpl extends ServiceImpl<ProductionProcessDao, ProductionProcess> implements ProductionProcessService {

    @Override
    public int add(ProductionProcessForm productionProcessForm) {

        //校验

        ProductionProcess productionProcess =new ProductionProcess();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(ProductionProcess.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(productionProcessForm, productionProcess, copyOptions);

        return baseMapper.insert(productionProcess);
    }

    @Override
    public List<ProductionProcessVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<ProductionProcessVO> pageList4app(Page page, Map<String, Object> params) {
        List<ProductionProcessVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public ProductionProcessVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    /**
     * 查询物料
     * @param collected sku列表
     * @return
     */
    @Override
    public List<ProductDetail> getSkuInfoBy(Set<String> collected, @Param("page") Page<ProductDetail> page, Map<String,Object> paramMap) {
        return baseMapper.getSkuInfoBy(collected, page,paramMap);
    }

    /**
     * 查询设备列表
     * @param idArray
     * @return
     */
    @Override
    public List<DeviceTypeForm> getDevicetTypeList(List<String> idArray) {
        return this.baseMapper.getDeviceTypeList(idArray);
    }

    @Override
    public List<DeviceOrWorkVo> fessionlist(List<String> list) {
        return baseMapper.fessionlist(list, "");
    }

    @Override
    public List<DeviceOrWorkVo> devicelist(List<String> list) {
        return baseMapper.devicelist(list, "");
    }

    @Override
    public ResBenchmarkBookEchnologyVo getBenEchnologyBy(Long bookId, String processName) {

        return this.baseMapper.getBenEchnologyBy(bookId,processName);
    }


    @Override
    public List<ResBenchmarkBookEchnologyVo> getBenEchnologyListBy(Long bookId) {
        return baseMapper.getBenEchnologyListBy(bookId);
    }
}
